package com.mud.mudcommune.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.mud.mudcommune.R;

import java.util.List;

/**
 * Created by welcome to china on 2016/12/12.
 */

public class BrowseRecordAdapter extends MyBaseAdapter {
    private List list;
    private Context context;

    public BrowseRecordAdapter(@NonNull List list, Context context) {
        super(list);
        this.list = list;
        this.context = context;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup viewGroup) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.browse_record_item, null);
            viewHolder = getViewHolder(convertView);
        }
        viewHolder = getViewHolder(convertView);
        viewHolder.title.setText("20款创意拉篮手机，最后一款跪服！");
        viewHolder.time.setText("15小时以前");
        viewHolder.image.setImageResource(R.mipmap.test01);
        return convertView;
    }

    public ViewHolder getViewHolder(View convertView) {
        ViewHolder viewHolder = null;
        viewHolder = (ViewHolder) convertView.getTag();
        if (viewHolder == null) {
            viewHolder = new ViewHolder(convertView);
        }
        return viewHolder;
    }

    static class ViewHolder {//NullPointerException
        private TextView title;
        private TextView time;
        private ImageView image;

        public ViewHolder(View convertView) {
            image = (ImageView) convertView.findViewById(R.id.recode_item_image);
            title = (TextView) convertView.findViewById(R.id.record_title);
            time = (TextView) convertView.findViewById(R.id.record_time);
            convertView.setTag(this);
        }
    }
}
